package tw.com.test01;

import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {

	private ListView list;
	private TextView title;
	SQLite db =new SQLite(this);
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		loadViews();
		addListeners();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	void loadViews(){
		db.open();
		Cursor cursor;
		cursor=db.query("select Subject_ID,Subject_Description from Subject");


		list = (ListView) findViewById(R.id.listView1);
		myUtil.Cursor2ListView(this,list,cursor,1);
		db.close();
		title= (TextView) findViewById(R.id.textView1);
		title.setText("text");
	}
	

    void addListeners(){
		list.setOnItemClickListener(listOnItemClick);

		title.setOnClickListener(titleOnClick);
	}
    private ListView.OnItemClickListener listOnItemClick = new ListView.OnItemClickListener()
    {

		public void onItemClick(AdapterView parent, View v, int position, long id){
    		String val;
    		val=((TextView)v).getText().toString();
    		title.setText(val/* "OnItemClick"*/);
 
    		Intent intent = new Intent();
    		intent.setClass(MainActivity.this, Condition.class );
    		intent.putExtra("subject", val);
    		startActivity(intent);
 
    	}
    };



    private TextView.OnClickListener titleOnClick=new TextView.OnClickListener(){
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			title.setText("Title OnClick");
		}
    };
}
